<template>
  <div>
    <el-dialog :title="title" :visible.sync="visible" width="400px" append-to-body custom-class="import-dialog">
      <div class="dialog-content">
        <p style="font-size: 16px;color: #666; text-align: center; margin-bottom: 20px">确定要关闭该客源吗？</p>
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
          <el-form-item label="关闭类型" prop="closeType">
            <el-radio-group v-model="form.closeType" size="mini">
              <el-radio-button label="1">已签约</el-radio-button>
              <el-radio-button label="2">无意向</el-radio-button>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="备注" prop="remark">
            <el-input type="textarea" v-model="form.remark" rows="3"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="close">取消</el-button>
        <el-button type="primary" size="small" @click="handleSubmit">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import { debounce } from '@/utils'
import { closeCluePool } from '@/api/cluePool/cluePool'

export default {
  props: {
    title: {
      default: '提示'
    },
    show: {
      default: false
    },
    data: {}
  },
  dicts: [],
  data() {
    return {
      form: {},
      rules: {
        closeType: [
          { required: true, message: '请选择关闭类型', trigger: 'blur' }
        ],
        remark: [
          { required: true, message: '请输入备注', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {
    visible: {
      get() {
        return this.show
      },
      set(val) {
        this.$emit('update:show', val)
      }
    }
  },
  watch: {
    show: {
      handler(newVal) {
        if (newVal) {
          this.init()
        }
      }
    }
  },
  methods: {
    init() {
      this.reset()
    },
    reset() {
      this.form = {
        'cluePoolId': this.data.cluePoolId, //线索池id
        'closeType': '1', //关闭类型：1.已签约、2.无意向
        'remark': '' //备注
      }
      this.resetForm('queryForm')
    },
    /** 确定 */
    handleSubmit: debounce(function() {
      console.log('handleSubmit', this.form)
      this.$refs.form.validate((valid) => {
        if (valid) {
          closeCluePool(this.form).then(res => {
            this.$message.success(res.msg || '提交成功')
            this.$emit('success')
            this.close()
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }, 500, true),
    close() {
      this.reset()
      this.visible = false
    }
  }
}
</script>

<style lang="scss" scoped>
@import "@/assets/styles/dialog.scss";
</style>
